﻿//TODO: VerticalIntensity: implement and Test

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using System.Drawing.Imaging;

using LowLevelGraphics.ColorSpaces;
using LowLevelGraphics.Histograms;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// Tries to remove all shadows.
    /// </summary>
    public class VerticalIntensity : BaseForeBackgroundColorFilter
    {
        protected Statistics m_Statistics = null;

        protected bool m_bIncludeStatistics = false;

        /// <summary>
        /// Initializes a new instance of the <see cref="VerticalIntensity"/> class.
        /// </summary>
        public VerticalIntensity()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="VerticalIntensity"/> class.
        /// </summary>
        /// <param name="_VerticalIntensity">The _VerticalIntensity.</param>
        internal VerticalIntensity(VerticalIntensity _VerticalIntensity)
        {
        }

        /// <summary>
        /// Execute this Filter
        /// A Debug Statement is written if a concrete Filter is called
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            int nHeight = _bitmap.Height;
            int nWidth = _bitmap.Width;

            int x = 0;
            int y = 0;

            for (x = 0; x < nWidth; x++)
            {
                int nSum = 0;
                int nRowPixels = 0;
                for (y = 0; y < nHeight; y++)
                {
                    Color color = _bitmap.GetPixel(x, y);
                    if (color != m_ColorBackground)
                    {
                        nRowPixels++;
                    }
                }
                for (y = 0; y < nRowPixels; y++)
                {
                    _bitmap.SetPixel(x, y, m_ColorForeground);
                }
                for (y = nRowPixels; y < nHeight; y++)
                {
                    _bitmap.SetPixel(x, y, m_ColorBackground);
                }
            }
            if (m_bIncludeStatistics) m_Statistics = new Statistics(_bitmap);
            return _bitmap;
        }

        /// <summary>
        /// Gets statistics
        /// </summary>
        public Statistics Statistics
        {
            get { return m_Statistics; }
        }

        /// <summary>
        /// This is used to clone a filter, each filter must implement it's own clone functionality
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new VerticalIntensity(this);
        }
    }
}
